/*
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <hash_map>
#include <set>
#include <vector>
#include <Stack>
#include <iostream>
#include <sstream>
using namespace std;

bool isScramble(string s1, string s2) {
	if(s1==""||s2==""||s1.length()!=s2.length()){
		return false;
	}
	if(s1==s2)
		return true;
	string t1=s1,t2=s2;
	sort(t1.begin(),t1.end());
	sort(t2.begin(),t2.end());
	for(int i=0;i<s1.length();i++){
		if(t1[i]!=t2[i])
			return false;
	}
	string s11,s12,s21,s22;
	bool res=false;
	for(int i=1;i<s1.length();i++){
		s11=s1.substr(0,i);
		s12=s1.substr(i,s1.length()-i);
		s21=s2.substr(0,i);
		s22=s2.substr(i,s1.length()-i);
		res=isScramble(s11,s21)&&isScramble(s12,s22);
		if(!res){
			s21=s2.substr(s1.length()-i,i);
			s22=s2.substr(0,s1.length()-i);
			res=isScramble(s11,s21)&&isScramble(s12,s22);
			if(res)
				return true;
		}else
			return true;
	}
	return res;
}
int main(){
	int a[]={1,3,-1,5,2,1};
	cout<<isScramble("great","rgtae");
	cout<<endl;
	system("pause");
}
*/